package cn.com.qiancheng.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import cn.com.qiancheng.dto.TrinerClass;
import cn.com.qiancheng.util.DbUtil;

public class TrinerClassDao {
	public TrinerClass sreachTrinerClass(int id){
		TrinerClass tc = null;
		try {
			Connection con = DbUtil.openConnection();
			String sql = "SELECT c_id,c_name FROM t_class WHERE c_id =?";
			PreparedStatement stat = con.prepareStatement(sql);
			stat.setInt(1, id);
			ResultSet rs = stat.executeQuery();
			if(rs.next()){
				tc = new TrinerClass();
				tc.setId(rs.getInt("c_id"));
				tc.setName(rs.getString("c_name"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				DbUtil.closeConnection();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return tc;
	}
	
	public TrinerClass sreachTrinerClass(String tclass){
		TrinerClass tc = null;
		try {
			Connection con = DbUtil.openConnection();
			String sql = "SELECT c_id,c_name FROM t_class WHERE c_name =?";
			PreparedStatement stat = con.prepareStatement(sql);
			stat.setString(1, tclass);
			ResultSet rs = stat.executeQuery();
			if(rs.next()){
				tc = new TrinerClass();
				tc.setId(rs.getInt("c_id"));
				tc.setName(rs.getString("c_name"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				DbUtil.closeConnection();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return tc;
	}
}
